package com.techsoul.common.core.config;

import com.techsoul.common.core.config.properties.IdWorkerProperties;
import com.techsoul.common.core.pojo.Result;
import com.techsoul.common.core.util.id.IdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.web.context.WebApplicationContext;

@Configuration
public class ComponentConfig {

    @Autowired
    private IdWorkerProperties idWorkerProperties;

    @Bean
    @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
    public Result result() {
        return new Result();
    }

    @Bean
    public IdWorker idWorker() {
        return new IdWorker(idWorkerProperties.getWorkerId(), idWorkerProperties.getDatacenterId());
    }

}
